<?php 
	class Branch extends CI_Controller{
		public function __construct(){
			parent::__construct();
		}
		
		public function branch_list($str=""){
			if($str != ""){
				$arr = array();
				$this->db->select("t2.pkid,t2.name_en,t2.address");
				$this->db->from("mobile_customer t1");
				$this->db->join("mobile_branch t2", "t1.pkid=t2.customer_pkid");
				$this->db->where("t1.name",$str);
				$this->db->where("t2.status",1);
				$res = $this->db->get()->result_array();
				foreach ($res as $P){
					$tmp['pkid']		=$P['pkid'];
					$tmp['title']		=stripslashes($P['name_en']);
					$tmp['address']		=stripslashes($P['address']);
					$this->db->where("branch_pkid",$P['pkid']);
					$this->db->order_by("pkid","asc");
					$this->db->limit(1);
					$rowimg = $this->db->get("mobile_branch_img")->row();
					$tmp['img']		=$rowimg->img;
					$arr[] = $tmp;
				}
				echo json_encode($arr);
			}
		}
		
		public function branch_detail($id){
			if($id != ""){
				$arr = array();
				$this->db->where("pkid",$id);
				$rows = $this->db->get("mobile_branch")->row();
				$tmp['title']			=$rows->name_en;
				$tmp['desc']			=$rows->description_en;
				$tmp['tel']				=$rows->tel;
				$arr[]  = $tmp;
				
				echo json_encode($arr);
			}
		}
		
		public function branch_img($id){
			if($id != ""){
				$arr = array();
				$this->db->where("branch_pkid",$id);
				$rows = $this->db->get("mobile_branch_img")->result_array();
				foreach ($rows as $P){
					$tmp['img']			=$P['img'];
					$arr[]  = $tmp;
				}
				echo json_encode($arr);
			}
		}
	}
?>